import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
axios.defaults.baseURL = 'http://127.0.0.1:7001'
// axios.post('/api/columns').then(res => {
//   console.log(res)
// })
axios.interceptors.request.use(config => {
  store.commit('setLoading', true)
  return config
})
axios.interceptors.response.use(config => {
  store.commit('setLoading', false)
  if (config.data.code !== 0 && config.data.errData.error) {
    store.commit('setError', { status: true, message: config.data.errData.error })
    setTimeout(() => {
      store.commit('setError', { status: false, message: '' })
    }, 0)
  }
  return config
}, e => {
  const { error } = e.response.data
  store.commit('setError', { status: true, message: error })
  store.commit('setLoading', false)
  setTimeout(() => {
    store.commit('setError', { status: false, message: '' })
  }, 0)
  return Promise.reject(error)
})

const app = createApp(App)
app.use(router)
app.use(store)
app.mount('#app')
